import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
import { resolve } from "node:path"
import dts from "vite-plugin-dts"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), vueJsx(), dts()],
  build: {
    outDir: "dist",
    assetsDir: "assets",
    sourcemap: true,
    lib: {
      name: "components-lib",
      entry: resolve(__dirname, "package/index.ts"),
      fileName: "components-lib",
      formats: ["es", "cjs"],
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ["vue"],
      // output: {
      //   //输出为es、cjs文件
      //   // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
      //   exports: "named",
      //   externalLiveBindings: false,
      //   globals: {
      //     vue: "Vue",
      //   },
      // },
      output: [
        //输出为es、cjs文件夹
        {
          format: "es",
          entryFileNames: "[name].js",
          preserveModules: true,
          dir: "dist/es",
          preserveModulesRoot: "src",
        },
        {
          format: "cjs",
          entryFileNames: "[name].js",
          preserveModules: true,
          dir: "dist/lib",
          preserveModulesRoot: "src",
        },
      ],
    },
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
      format: {
        comments: false,
      },
    },
    // cssCodeSplit:true
  },
})
